package com.love_weinuo.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.WindowManager;

import com.tencent.qcloud.uikit.common.component.video.util.LogUtil;
import com.love_weinuo.R;
import com.love_weinuo.databinding.ActivitySplashBinding;
import com.love_weinuo.ui.MainActivity;
import com.love_weinuo.ui.view.chat.ILoginView;
import com.love_weinuo.ui.view.chat.PojoLoginPresenter;
import com.love_weinuo.util.BHThreadPool;
import com.love_weinuo.util.SpUtils;

/**
 * Created by Administrator
 * on 2019/2/22.
 */

public class SplashActivity extends Activity implements ILoginView {

    ActivitySplashBinding binding;
    boolean canUse = true;
    final String isLogin = (String) SpUtils.get("isLogin", "");
    String isFirst = (String) SpUtils.get("module_is_first","");
    PojoLoginPresenter mPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_splash);
        binding.setActivity(this);
        initView();
    }

    private void initView() {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                if (canUse) {
                    SystemClock.sleep(2000);
                    if (!"yes".equals(isFirst)) {
                        startActivity(new Intent(SplashActivity.this,GuideActivity.class));
                        finish();
                    }else{
                        if (TextUtils.isEmpty(isLogin)) {
                            startActivity(new Intent(SplashActivity.this, LoginActivity.class));
                            finish();
                        } else {
                            startActivity(new Intent(SplashActivity.this, MainActivity.class));
                            finish();
                        }
                    }
                }
            }
        };
        BHThreadPool.getInstance().executeTask(runnable);
    }

    @Override
    public void onLoginSuccess(Object res) {
        LogUtil.e("IM登录成功" + res.toString());
    }

    @Override
    public void onLoginFail(String module, int errCode, String errMsg) {
        LogUtil.e("登录失败" + module + " 失败错误==》" + errCode + "  错误信息==》" + errMsg);
    }

    @Override
    public void onRegisterSuccess(Object res) {
        LogUtil.e("注册成功" + res.toString());
    }

    @Override
    public void onRegisterFail(String module, int errCode, String errMsg) {
        LogUtil.e("注册失败" + module.toString() + " 错误码==>" + errCode + " 错误信息==>" + errMsg);
    }
}
